/**
 * @Title: MyDemoTest.java
 * @Package: mrunit
 * @Description: TODO(用一句话描述该文件做什么)
 * @author: zhangyimin
 * @date: 2018年8月2日 下午6:03:19
 * @version: V1.0
 */
package mrunit;

import mapper.HadoopMapper;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mrunit.mapreduce.MapDriver;
import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
import org.junit.Test;
import reducer.HadoopReducer;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: MyDemoTest
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author: zhangyimin
 * @date: 2018年8月2日 下午6:03:19
 */

public class MyDemoTest {

    @Test
    public void testMapper() throws Exception {
        HadoopMapper hadoopMapper = new HadoopMapper();
//		HadoopReducer hadoopReducer=new HadoopReducer();
        MapDriver<LongWritable, Text, Text, LongWritable> mapDriver = new MapDriver<>(hadoopMapper);
        mapDriver.withInput(new LongWritable(1), new Text("I love Beijing"));
        mapDriver.withOutput(new Text("I"), new LongWritable(1))
                .withOutput(new Text("love"), new LongWritable(1))
                .withOutput(new Text("Beijing"), new LongWritable(1));
        mapDriver.runTest();

    }

    @Test
    public void testReducer() throws Exception {
//        HadoopMapper hadoopMapper = new HadoopMapper();
        HadoopReducer hadoopReducer = new HadoopReducer();
        ReduceDriver<Text, LongWritable, Text, LongWritable> reduceDriver = new ReduceDriver<>(hadoopReducer);
        List<LongWritable> list = new ArrayList<>();
        list.add(new LongWritable(1));
        list.add(new LongWritable(1));
        list.add(new LongWritable(1));
        reduceDriver.withInput(new Text("Beijing"), list);
        reduceDriver.withOutput(new Text("Beijing"), new LongWritable(3));
        reduceDriver.runTest();

    }


}
